11. Exercise: RegEx

RegEx Exercise

Task Description:

Follow the steps below to create a RegEx example to validate an email.

Task List:

Task Feedback:

Nice work!

Solution

Here is the RegEx solution. Your solution may differ, but it should look similar and have the same components such as Pattern and Matcher to validate.

public class RegExTester {

  public static void main(String[] args){
      String emailRegex = "^(.+)@(.+).(.+)$";
      Pattern pattern = Pattern.compile(emailRegex);
      String email = "jeff@gmail.com";

      System.out.println(pattern.matcher(email).matches());
  }
}